package com.lucky.contract.controller;

import com.lucky.contract.common.ResultModel;
import com.lucky.contract.entity.ResultMap;
import com.lucky.contract.service.ConstructService;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping(value = "/construct")
public class ConstructController {

    private Logger log = LoggerFactory.getLogger(this.getClass());

    @Resource
    private ConstructService constructService;

    @RequestMapping(value = "/list")
    public ModelAndView getConstructList(ModelAndView model){
        model.setViewName("/construct/list");
        return model;
    }

   @RequestMapping(value = "/data_list")
   @ResponseBody
   public Object getConstructContractList(Integer pageSize, Integer pageNo, String queryValue, ResultModel result){
       Map<String, Object> params = new HashMap<>();
       ResultMap resultMap = new ResultMap();
       try {
           if(pageSize <= 0)
               pageSize = 10;
           if(pageNo <= 0)
               pageNo = 1;
           params.put("pageSize",pageSize);
           params.put("start",(pageNo - 1) * pageSize);
           if(StringUtils.isNotBlank(queryValue))
               params.put("searchValue","%" + queryValue + "%");
           resultMap = constructService.queryPageList(params);
       } catch (Exception e) {
           e.printStackTrace();
           resultMap.catchException(e);
           log.error("查询建设合同列表失败，原因：" + e.getMessage());
       }
       return result;
   }

}
